var e = require("./libs/qqmap-wx-jssdk.js");

Page({
    data: {
        location_text: "正在获取",
        temperature: "0",
        now_weather: "正在获取",
        now_air: "优",
        today: "2019-09-12",
        today_weather: "晴转多云",
        wind_air: "西北",
        wind_sc: "3-4",
        futuretemperature: "4",
        futurenow_weather: "futurenow_weather",
        futuretoday: "2019-11-12",
        futurewind: "xinande",
        hum: ""
    },
    onLoad: function() {
        this.qqmapsdk = new e({
            key: "TXIBZ-L2BKG-Q3QQE-IB7A7-33YT6-2MBXY"
        }), this.getCityAndWeather();
    },
    getCityAndWeather: function() {
        var e = this, t = this;
        wx.getLocation({
            success: function(a) {
                e.location_pin = a.longitude + "," + a.latitude, e.qqmapsdk.reverseGeocoder({
                    location: {
                        latitude: a.latitude,
                        longitude: a.longitude
                    },
                    success: function(a) {
                        e.city2 = a.result.address_component.city;
                        var o = a.result.address_component.city;
                        t.setData({
                            location_text: o
                        }), t.getNowWeather(), t.getFutureWeather(), t.getNowAir();
                    }
                });
            },
            fail: function() {
                console.log("未授权位置");
            }
        });
    },
    getNowWeather: function() {
        var e = this, t = "https://free-api.heweather.net/s6/weather/now?key=9d6a9102c9074079bebcb99c393f57ba&location=" + this.location_pin;
        wx.request({
            url: t,
            success: function(t) {
                console.log("success"), console.log(t);
                var a = t.data.HeWeather6[0].now, o = a.tmp, n = a.cond_txt, r = a.wind_dir, i = a.wind_sc, c = a.hum, s = new Date(), u = s.getFullYear(), l = s.getMonth() + 1, d = s.getDate();
                e.setData({
                    hum: c,
                    temperature: o,
                    now_weather: n,
                    today: u + "年" + l + "月" + d + "日",
                    wind: r + i + "级"
                });
            },
            fail: function(e) {
                console.log();
            }
        });
    },
    getFutureWeather: function() {
        var e = this, t = "https://free-api.heweather.net/s6/weather/forecast?key=9d6a9102c9074079bebcb99c393f57ba&location=" + this.location_pin;
        wx.request({
            url: t,
            success: function(t) {
                console.log("success"), console.log(t);
                var a = t.data.HeWeather6[0].daily_forecast, o = a.tmp_max, n = a.cond_txt_d, r = (a.wind_sc, 
                new Date()), i = r.getFullYear(), c = r.getMonth() + 1, s = r.getDate();
                e.setData({
                    futureData: a,
                    futuretemperature: o,
                    futurenow_weather: n,
                    futuretoday: i + "年" + c + "月" + s + "日"
                });
            },
            fail: function(e) {
                console.log();
            }
        });
    },
    getNowAir: function() {
        var e = this, t = "https://free-api.heweather.net/s6/air/now?key=9d6a9102c9074079bebcb99c393f57ba&location=" + this.city2 + ",";
        wx.request({
            url: t,
            success: function(t) {
                console.log("success"), console.log(t);
                var a = t.data.HeWeather6[0].air_now_city, o = a.qlty, n = a.pm25, r = new Date();
                r.getFullYear(), r.getMonth(), r.getDate();
                e.setData({
                    airData: a,
                    qlty: o,
                    pm25: n
                });
            },
            fail: function(e) {
                console.log();
            }
        });
    },
    gengduo: function() {
        wx.navigateToMiniProgram({
            appId: "wx8a2018a116c81bab"
        });
    }
});